<!DOCTYPE html>
<title>Test fenced frame does not allow to register background sync</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<body>

<script>
const background_sync_register_key = KEYS['background-sync'];

function base_path() {
  return location.pathname.replace(/\/[^\/]*$/, '/');
}

async function test(url, message) {
  attachFencedFrame(url)

  // Get the result for the top-level fenced frame.
  const fenced_frame_result =
      await nextValueFromServer(background_sync_register_key);
  assert_equals(fenced_frame_result, 'failed', message);
}

promise_test(async (t) => {
  const fencedFrameUrl = 'resources/background-sync-inner.https.html';
  await test(
      fencedFrameUrl,
      'background sync registration is disallowed inside a same-origin fenced frame');

  const CROSS_ORIGIN_DESTINATION =
      get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() + fencedFrameUrl;
  await test(
      CROSS_ORIGIN_DESTINATION,
      'background sync registration is disallowed inside a cross-origin fenced frame');
}, 'navigator.serviceWorker.register');
</script>

</body>
